package com.ding.easycontroller.helper;

import org.springframework.http.HttpHeaders;
import org.springframework.web.socket.*;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.Principal;
import java.util.List;
import java.util.Map;

public class EcSession implements WebSocketSession {

    private WebSocketSession core;

    public EcSession(WebSocketSession core) {
        this.core = core;
    }

    synchronized
    public void send(String msg) {
        try {
            core.sendMessage(new TextMessage(msg));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Override
    public String getId() {
        return core.getId();
    }

    @Override
    public URI getUri() {
        return core.getUri();
    }

    @Override
    public HttpHeaders getHandshakeHeaders() {
        return core.getHandshakeHeaders();
    }

    @Override
    public Map<String, Object> getAttributes() {
        return core.getAttributes();
    }

    @Override
    public Principal getPrincipal() {
        return core.getPrincipal();
    }

    @Override
    public InetSocketAddress getLocalAddress() {
        return core.getLocalAddress();
    }

    @Override
    public InetSocketAddress getRemoteAddress() {
        return core.getRemoteAddress();
    }

    @Override
    public String getAcceptedProtocol() {
        return core.getAcceptedProtocol();
    }

    @Override
    public void setTextMessageSizeLimit(int i) {
        core.setTextMessageSizeLimit(i);
    }

    @Override
    public int getTextMessageSizeLimit() {
        return core.getTextMessageSizeLimit();
    }

    @Override
    public void setBinaryMessageSizeLimit(int i) {
        core.setBinaryMessageSizeLimit(i);
    }

    @Override
    public int getBinaryMessageSizeLimit() {
        return core.getBinaryMessageSizeLimit();
    }

    @Override
    public List<WebSocketExtension> getExtensions() {
        return core.getExtensions();
    }

    @Override
    public void sendMessage(WebSocketMessage<?> webSocketMessage) throws IOException {
        core.sendMessage(webSocketMessage);
    }

    @Override
    public boolean isOpen() {
        return core.isOpen();
    }

    @Override
    public void close() throws IOException {
        core.close();
    }

    @Override
    public void close(CloseStatus closeStatus) throws IOException {
        core.close(closeStatus);
    }
}
